function converged = Check_convergence(k, x_k, x_kk, options, verbose)
% converged = Check_convergence(k, x_k, x_kk, options, verbose)
% 
% Check_convergence checkes convergence for an optimization algorithm.
%
% See also: L_BFGS
%
% 2013-07-25 --------------------------------------------------------------
% 
% Matthias J. Ehrhardt
% CMIC, University College London, UK
% 
% matthias.ehrhardt.11@ucl.ac.uk
% 
% -------------------------------------------------------------------------

    converged = false;

    dx_k = norm(x_k - x_kk, 'inf');
    if dx_k < options.x_tolerance
        if verbose; fprintf('   >>> Converged! (because the iterate %i changes less (%3.2e) than the tolerance (%3.2e) at any pixel)\n', k, dx_k, options.x_tolerance); end;
        converged = true;
    end
end